angular.module('U9ImHd.services')

.factory('RegisterService', ['$q', 'Http', 'APPCONSTANTS',
    function($q, Http, APPCONSTANTS) {
        var o = {},
            _stations;

        o.getStation = function () {
            var defer = $q.defer();

            if (_stations) {
                defer.resolve(_stations);
            } else {
                Http.post({url: APPCONSTANTS.getStationURL}).then(function (stations) {
                    _stations = stations;
                    defer.resolve(stations);
                }, function (err) {
                    defer.reject(err);
                });
            }

            return defer.promise;
        };
        o.registerTerminal = function (terminalUniqueID, workLocationID) {
            var defer = $q.defer();

            Http.post({
                url: APPCONSTANTS.registerTerminalURL,
                data: {
                    Parameter: {
                        TerminalUniqueID: terminalUniqueID,
                        WorkLocationID: workLocationID
                    }
                }
            }).then(function () {
                defer.resolve();
            }, function (err) {
                defer.reject(err);
            });

            return defer.promise;
        };

        return o;
    }
]);
